// TOWN SCRIPT
//    Town 5: Underground

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documentation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

body;

beginstate INIT_STATE;
// Called upon entering

//intro text
if(get_flag(5,0) == 0) {
	reset_dialog();
	add_dialog_str(0,"As you grope around in the dark, you hear the caves spring to life around you. You hear a rushing noise, and a rustle of movement, and a rasping laugh fills the air. Suddenly, it stops, and addresses you.",0);
	add_dialog_str(1,"_Ahh, thank you. Freedom, at last. And, as a reward we will try to be gentle as we feast upon you!_",0);
	add_dialog_str(2,"You frantically look around, but the cave is too dark to see anything. You need to get out of here, and quickly...",0);
	run_dialog(1);
	set_flag(5,0,1);
}
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// Called every turn.

break;

//Broken crystal
beginstate 10;
	if(get_flag(5,1) == 0) {
		message_dialog("You approach the shattered remains of the crystal spire - when you struck it it exploded with such a force that all that is left is a charred lump, still gently smoking.","There is nothing else here for you to do, so you move on.");
		set_flag(5,1,1);
		block_entry(1);
	} else {
		message_dialog("There is nothing here for you to do, so you move on.","");
		block_entry(1);
	}
break;

//Northern chest
beginstate 11;
	if(get_flag(4,6) == 0) {
		message_dialog("This stone chest is empty, apart from a few broken tools and old lamp casings. Needless to say, none of it is of any use to you. You close the chest and move on.","");
		set_flag(4,6,1);
		block_entry(1);
	} else {
		message_dialog("You have already looked in here.","");
		block_entry(1);
	}
break;

//Southern Box
beginstate 12;
	if(get_flag(4,7) == 0) {
		reset_dialog();
		add_dialog_str(0,"This stone chest is mostly full of broken tools and other assorted rubbish. However, tucked away at the bottom, wrapped in a dirty old cloth, you find a small crystal.",0);
		add_dialog_str(1,"You lift it out, and look it over. It feels warm to the touch and vibrates slightly in your hand - it must be a shattering stone, a powerful device capable of smashing down unstable walls. Do you take it with you?",0);
		add_dialog_choice(0,"Yes, take the crystal.");
		add_dialog_choice(1,"No, leave it alone.");
		if(run_dialog(1) == 1) {
			message_dialog("You take the crystal, and close the chest behind you.","");
			reward_give(328);
			set_flag(4,7,1);
			end();
		} else {
			message_dialog("You put the crystal back - although it seems to be alright still, it has been locked away for a very long time - the last thing you need now is it exploding in your face when you try to use it.","You close the chest and move on.");
			end();
		}
	}
break;	

//Ladder up
beginstate 13;
	message_dialog("You reach the bottom of the ladder and look up - fortunately whatever was obstructing the top of the chute before is gone - your way is clear.","Quickly, without looking back, you climb the ladder and emerge in the temple.");
	move_to_new_town(3,21,20);
break;

//damage 1
beginstate 14;
	if(get_flag(5,2) == 0) {
		message_dialog("As you stumble through the dark you feel something smash into you, throwing you off balance. You quickly struggle back up to your feet and swing your weapon around, but fail to connect with anything.","");
		set_flag(5,2,1);
		damage_char(1000,20,4);
	}	
break;

//damage 2
beginstate 15;
if(get_flag(250,0) == 0) {
	if(get_flag(5,3) == 0) {
		message_dialog("Once again you feel something smash into your back, knocking you into the cavern wall. You quickly struggle back up to your feet and swing your weapon around, but again, you fail to connect with anything.","");
		set_flag(5,3,1);
		damage_char(1000,20,4);
	}	
}
break;

//damage 3
beginstate 16;
if(get_flag(250,0) == 0) {
	if(get_flag(5,4) == 0) {
		message_dialog("Again, you are hit in the chest, hard. You stumble back, and swing your weapon, but you fail to hit anything...","This is crazy - there is no way you're going to be able to beat these monsters in combat. You'll have to trap them somehow...");
		set_flag(5,4,1);
		damage_char(1000,20,4);
	}	
}
break;

//damage 4. rubble
beginstate 17;
if(get_flag(250,0) == 0) {
	if(get_flag(5,5) == 0) {
		message_dialog("You turn this corner and are once again attacked. Frantically you get to your feet, when suddenly you see something up ahead...","One of the stone buildings in the cavern to the west has heavily cracked walls. If you could get inside, and get the angels to follow you, you might be able to bring the walls down and trick them into looking at each other.");
		message_dialog("However, you would have to make sure you could smash the walls before you entered the small building - there would be no way back out without the angels getting you...","");
		set_flag(5,5,1);
		damage_char(1000,20,4);
	}
}
break;

//Stop them leaving
beginstate 18;
	if(get_flag(250,0) == 0) {
		reset_dialog();
		add_dialog_str(0,"As you try to run along this passage, you hear a slamming sound from ahead. As it is too dark to see anything properly, you assume that an angel must have been waiting up ahead to stop you from escaping.",0);
		add_dialog_str(1,"Whilst you could probably carry on down the tunnel, you will almost certainly be wide open to attack from the angel ahead. Turning back would probably be safer than trying to push past, but the choice is yours.",0);
		add_dialog_str(2,"What do you wish to do? Carry on down the passage, and try to get past the angel ahead, or turn back?",0);
		add_dialog_choice(0,"Yes, carry on.");
		add_dialog_choice(1,"No, turn back.");
		if(run_dialog(1) == 1) { 
			message_dialog("As you try to get down this passage you are shoved back harshly. You fall, and smash your head against the rocky floor. As you drift out of consciousness, your eyes focus on a looming figure just in front of you, it's hands reaching out.","Fortunately, at that moment, you pass out. You do not wake up.");
			kill_char(1000,0,0);
		} else {
			message_dialog("You turn back, heading into the large cavern with the two buildings.","");
			block_entry(1);
		}
	}	
break;

//crypt
beginstate 19;
	if(get_flag(5,6) == 0) {
		message_dialog("You run into the crypt and breathe in heavily. The angels are stuck, and you're safe, if a little bruised.","You examine the key you took from around one of the angel's neck. It doesn't appear special in anyway, but you have a feeling it'll get you past the portcullis in the town above.");
		set_flag(5,6,1);
	}	
break;

//inside crypt
beginstate 20;
if(get_flag(250,0) == 0) {
	if(get_flag(5,7) == 0) {
		message_dialog("You rush inside this small crypt and back up against the wall, keeping your eyes fixed on the doorway. Almost immediately you hear the angels slamming themselves against the crumbling walls outside.","If you had some way to destroy the walls, you'd be able to trick the angels into facing each other, trapping them as statues forever...");
		relocate_character(0,10,38);
		relocate_character(1,10,39);
		relocate_character(2,10,40);
		relocate_character(3,9,40);
		block_entry(1);
		set_flag(5,7,1);
	}
}
break;

//Kill them if they didn't use the crystal
beginstate 21;
	if(get_flag(5,7) == 1) { //have entered room
		if(get_flag(250,0) == 0) { //not killed them
			reset_dialog();
			add_dialog_str(0,"You cautiously approach the doorway, trying hard not to blink lest an angel manages to get close enough to injure, or worse, kill, you - you can still hear them moving outside, furiously hammering the crumbling walls.",0);
			add_dialog_str(1,"If you went out, it's almost a certainty that they will be able to sneak around you before you have time to do anything. Still, if you've no way of crumbling the walls you don't really have a choice...",0);
			add_dialog_str(2,"Do you wish to leave the building?",0);
			add_dialog_choice(0,"Yes, leave.");
			add_dialog_choice(1,"No, stay here.");
			if(run_dialog(1) == 1) {
				message_dialog("The moment you step outside you are set upon by several harsh, hungry hands. They tear and claw at you, before smashing you into the wall of the building you just left.","You pass out, and never wake up.");
				kill_char(1000,0,0);
			} else {
				message_dialog("You back away from the door, into the relative safety of the small crypt.","");
				block_entry(1);
			}
	}
}
break;

//Angel
beginstate 22;
	if(get_flag(250,0) == 1) {
		message_dialog("You approach the statue and look it over. Despite being completely still, and now trapped, it is terrifying. The dull, lifeless eyes, the grasping, clawing hands, and the snarling curl of the lips all combine to make something truly fearsome.","With an involuntary shudder, you turn away - being careful not to block it from the view of the other statues, just in case it breaks loose.");
	}
break;